﻿using LxCore;
using System;
using System.Reflection;

namespace LxCore
{
    public class FvJointList : JsIdentifyList<FvJoint>
    {
        public override void Add(FvJoint item)
        {
            base.Add(item);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.JointConds.Add(new JointCond(item));
                LxSim.Sim.Fields.JointFields.Add(new JointCFDFields(item));
            }
        }
        public override void Insert(int index, FvJoint item)
        {
            base.Insert(index, item);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.JointConds.Insert(index, new JointCond(item));
                LxSim.Sim.Fields.JointFields.Insert(index, new JointCFDFields(item));
            }
        }
        public override void RemoveAt(int index)
        {
            base.RemoveAt(index);
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.JointConds.RemoveAt(index);
                LxSim.Sim.Fields.JointFields.RemoveAt(index);
            }
        }
        public override bool Remove(FvJoint item)
        {
            throw new NotImplementedException();
            return base.Remove(item);
        }
        public override void Clear()
        {
            base.Clear();
            if (isSimMesh())
            {
                LxSim.Sim.Conditions.JointConds.Clear();
                LxSim.Sim.Fields.JointFields.Clear();
            }
        }
        protected bool isSimMesh()
        {
            return ReferenceEquals(this, LxSim.Sim.Mesh.Joints);
        }
    }
}
